package com.HUT;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        //1.BM13判断是不是完全二叉树
        Queue<TreeNode> queue = new LinkedList<>();
        public boolean isCompleteTree (TreeNode root) {
            TreeNode cur = null;
            if (root == null) {
                return true;
            }
            queue.offer(root);
            while (!queue.isEmpty()) {
                cur = queue.poll();
                if (cur != null) {
                    queue.offer(cur.left);
                    queue.offer(cur.right);
                } else {
                    break;
                }
            }
            while(!queue.isEmpty()) {
                if(queue.poll() != null) {
                    return false;
                }
            }
            return true;
        }
        //2.BM6最长无重复子数组
        public int maxLength (int[] arr) {
            HashMap<Integer,Integer> map = new HashMap<>();
            int ret = 0;
            for(int left = 0,right = 0;right < arr.length;right++) {
                if(map.containsKey(arr[right])) {
                    map.put(arr[right],map.get(arr[right])+1);
                } else {
                    map.put(arr[right],1);
                }
                while(map.get(arr[right]) > 1) {
                    map.put(arr[left],map.get(arr[left++]) - 1);
                }
                ret = Math.max(ret,right - left +1);
            }
            return ret;
        }
    }
}